import numpy as np
import pandas as pd

rawdata=pd.read_csv("../log/rawdatatrain.csv")
misstrain=pd.read_csv('../log/datatraintrace1.csv')
misstest=pd.read_csv('../log/datatesttrace2.csv')

rawdata=rawdata.values
misstrain=misstrain.values
misstest=misstest.values

def nptolist(npdata):
    l1 = []
    n = 0
    for i in npdata:
        l2 = []
        for j in i:
            if isinstance(j, str):
                l2.append(j)
        l1.append(l2)
        n += 1
    print("***********")
    return l1

def tracetostream(data):
    list=[]
    for i in range(len(data)):
        for j in data[i]:
            l = []
            l.append('case'+str(i))
            l.append(j)
            list.append(l)
    return list

rawdata=nptolist(rawdata)
misstrain=nptolist(misstrain)
misstest=nptolist(misstest)

rawlist=tracetostream(rawdata)

misstrlist=tracetostream(misstrain)

misstelist=tracetostream(misstest)

rawlist=pd.DataFrame(rawlist)
misstrlist=pd.DataFrame(misstrlist)
misstelist=pd.DataFrame(misstelist)

rawlist.columns=['caseid','event']
misstrlist.columns=['caseid','event']
misstelist.columns=['caseid','event']
rawlist.to_csv('../log/rawxes.csv',index=False)
misstrlist.to_csv('../log/trainxes.csv',index=False)
misstelist.to_csv('../log/testxes.csv',index=False)

